package com.xjh.him.controller;

import com.xjh.him.annotation.LoginVerify;
import com.xjh.him.dto.usergroupmsg.UserGroupMsgDTO;
import com.xjh.him.dto.usergroupmsg.UserGroupMsgQueryDTO;
import com.xjh.him.service.UserGroupMsgServiceImpl;
import com.xjh.him.vo.usergroupmsg.UserGroupMsgQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xjh.tool.Checks;
import org.xjh.tool.common.ErrorMsg;
import org.xjh.tool.dto.ResultDTO;
import org.xjh.tool.vo.AjaxResultVO;

import java.util.List;

@RestController
@RequestMapping("/user/group/msg")
public class UserGroupMsgController {

    @Autowired
    private UserGroupMsgServiceImpl userGroupMsgService;


    @LoginVerify
    @RequestMapping("/list")
    public AjaxResultVO listMsg(@RequestBody UserGroupMsgQueryVO queryVO) {
        if (Checks.isAnyEmpty(queryVO, queryVO.getGroupId())) {
            return AjaxResultVO.getFailureResult(ErrorMsg.ERR_PARAMETER_IS_NULL);
        }
        UserGroupMsgQueryDTO queryDTO = new UserGroupMsgQueryDTO();
        queryDTO.setGroupId(queryVO.getGroupId());
        queryDTO.setLimit(queryVO.getPerPageSize());
        queryDTO.setSkip((queryVO.getPage() - 1) * queryVO.getPage());
        ResultDTO<List<UserGroupMsgDTO>> resultDTO = userGroupMsgService.listMsg(queryDTO);
        if (resultDTO.isSuccess()) {
            return AjaxResultVO.getSuccessResult(resultDTO.getResult());
        }
        return AjaxResultVO.getFailureResult(resultDTO.getErrMsg());
    }
}
